package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车模块管理")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody  ShoppingCartDTO dto ){
        shoppingCartService.add(dto);
        return Result.success();
    }


    /**
     * 查询购物车
     */
    @GetMapping("/list")
    public Result list(){
      List<ShoppingCart> cartList = shoppingCartService.list();
      return Result.success(cartList);
    }
    /**
     * 清空购物车
     */
    @DeleteMapping("/clean")
    public Result clean(){
         shoppingCartService.clean();
        return Result.success();
    }
    /**
     * 减少购物车
     * @param dto
     * @return
     */
    @PostMapping("/sub")
    public Result sub(@RequestBody  ShoppingCartDTO dto ){
        shoppingCartService.sub(dto);
        return Result.success();
    }

}
